package com.test.serviceribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class HelloServce {

    @Autowired
    private  RestTemplate restTemplate;

    //添加断路器配置
    @HystrixCommand(fallbackMethod = "hiError")     //@HystrixCommand注解。该注解对该方法创建了熔断器的功能，并指定了fallbackMethod熔断方法
    public String home(String name){
        return restTemplate.getForObject("http://eureka-client/hi?name="+name,String.class);
    }

    public String hiError(String name){
        return "Hi,你好"+name+"，so sorry!";
    }
}
